import Vue from 'vue';
import VueRouter from 'vue-router';
import { sync } from 'vuex-router-sync';
import TDesign from 'tdesign-vue';
import tab from '@/utils/tab';
import App from './App.vue';
import router from './router/index';
import filters from './filters'
import directive from './directive'
// import api from '@/api';
import { download } from '@/utils/request'
import { handleTree, handleDisabledTree, handleQuery, handleTheme } from "@/utils/common";
// import DictData from '@/components/DictData';
import '@/style/index.less';

import './permission';
import store from './store';
import pdf from 'vue-pdf-embed/dist/vue2-pdf-embed'
// eCharts组件
import eChartFn from '@/components/Chart';
import eChartPanel from '@/components/Chart/index.vue';

// 全局过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})


// 全局组件挂载
Vue.component(eChartPanel.name, eChartPanel)
Vue.component('pdf', pdf);


// 全局方法挂载
Vue.prototype.$filters = Vue.options.filters;
Vue.prototype.$tab = tab;
// Vue.prototype.$api = api; //App.vue line 47 登录后初始化
Vue.prototype.handleTree = handleTree;
Vue.prototype.handelQuery = handleQuery;
Vue.prototype.handleTheme = handleTheme;
Vue.prototype.handleDisabledTree = handleDisabledTree;
Vue.prototype.$eChartFn = eChartFn;
Vue.prototype.$download = download


Vue.use(VueRouter);
Vue.use(TDesign);
Vue.use(directive);
// Vue.use(DictData);

// Vue.prototype.$message = MessagePlugin
// MessagePlugin.config({
//   duration: 2000
// });

const originPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originPush.call(this, location).catch((err) => err);
};

const originReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originReplace.call(this, location).catch((err) => err);
};
// Vue.config.errorHandler =  (err, vm, info) =>{
//   // MessagePlugin.error(`错误: ${err.toString()}\n错误信息: ${info}`)
//   console.log(`错误: ${err.toString()}\n错误信息: ${info}`);
//   // console.log(vm)
// };

const isDebug = process.env.NODE_ENV !== 'production';
Vue.config.debug = isDebug;
Vue.config.devtools = isDebug;
Vue.config.productionTip = false;
sync(store, router);
new Vue({
  router,
  store,
  render: (h) => (
    <div>
      {/* 可以通过config-provider提供全局（多语言、全局属性）配置，如
      <t-config-provider globalConfig={enConfig}> */}
      <t-config-provider globalConfig={{ animation: { exclude: ['ripple'] } }}>
        <App />
      </t-config-provider>
    </div>
  ),
}).$mount('#app');
